package com.example.travel.controller;

import com.example.travel.entity.Hotel;
import com.example.travel.entity.Orderform;
import com.example.travel.entity.User;
import com.example.travel.entity.dto.*;
import com.example.travel.service.IAdminInsertService;
import com.example.travel.service.IAdminUpdateService;
import com.example.travel.util.ResultUtil;
import com.example.travel.util.UploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/AdminInsertController")
public class AdminInsertController {

    @Autowired
    private IAdminInsertService adminInsertService;

    @Autowired
    private UploadUtil uploadUtil;

    /**
     * 上传图片
     * @param hotelDTO
     * @return
     * @throws IOException
     */
    @PostMapping("/uploadImg")
    public ResultUtil uploadImg(HotelDTO hotelDTO) throws IOException {
        String uploadName = null;
        if(hotelDTO.getFile() != null){
            uploadName = uploadUtil.upload(hotelDTO.getFile());
        }
        return ResultUtil.ok(uploadName);
    }


    /**
     * 添加酒店信息
     * @param hotelDTO
     * @return
     * @throws IOException
     */
    @PostMapping("/insertHotelInformation")
    public boolean insertHotelInformation(HotelDTO hotelDTO){
        return adminInsertService.insertHotelInformation(hotelDTO);
    }

    /**
     * 添加景点信息
     * @param scenicDTO
     * @return 自增主键ID
     */
    @PostMapping("/insertScenicInformation")
    public int insertScenicInformation(ScenicDTO scenicDTO){
        return adminInsertService.insertScenicInformation(scenicDTO);
    }

    /**
     * 上传景点图片
     * @param scenicImgDTO
     * @return
     * @throws IOException
     */
    @PostMapping("/uploadScenicImg")
    public ResultUtil uploadScenicImg(ScenicImgDTO scenicImgDTO) throws IOException {
        String uploadName =uploadUtil.upload(scenicImgDTO.getFile());
        scenicImgDTO.setImgAddress(uploadName);
        return ResultUtil.ok(adminInsertService.uploadScenicImg(scenicImgDTO));
    }

    /**
     * 添加节日信息
     * @param festivalDTO
     * @return
     */
    @PostMapping("/insertFestivalInfomation")
    public boolean insertFestivalInfomation(FestivalDTO festivalDTO){
        return adminInsertService.insertFestivalInfomation(festivalDTO);
    }



}
